#!/usr/bin/env python

class Buffer :
    def __init__(self,bufsize):
        self.bufsize = bufsize
        self.buffer = {}

    def __len__(self):
        return len(self.buffer.values())

    def add(self,key,item):
        self.buffer[key] = item

    def has_element(self,key):
        return self.buffer.has_key(key)

    def update_element(self,key, w,eps=0.0):
        element = self.buffer[key]
        self.buffer[key] = (key, w + element[1], eps + element[2])

    def clear(self):
        self.buffer.clear()

    def get_buffer(self):
        return self.buffer

    def get_item(self,key):
		return self.buffer.get(key)